package com.sample.springbatch.job.sample.service;

import com.sample.springbatch.job.sample.writer.RepayOrderFlatFileItemWriter;
import com.sample.springbatch.job.sample.writer.RepayOrderMultiResourceFlatFileItemWriter;
import com.sample.springbatch.job.sample.writer.RepayOrderNewFlatFileItemWriter;
import com.sample.springbatch.job.sample.writer.RepayOrderNewMultiResourceFlatFileItemWriter;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.classify.BackToBackPatternClassifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zwg on 2017/10/31.
 */
@Component
public class RepayOrderBackToBackPatternClassifier extends BackToBackPatternClassifier {

    @Autowired
    RepayOrderRouterClassifiter repayOrderRouterClassifiter;

    @Autowired
    RepayOrderFlatFileItemWriter repayOrderFlatFileItemWriter;

    @Autowired
    RepayOrderNewFlatFileItemWriter repayOrderNewFlatFileItemWriter;

    @Autowired
    RepayOrderMultiResourceFlatFileItemWriter repayOrderMultiResourceFlatFileItemWriter;

    @Autowired
    RepayOrderNewMultiResourceFlatFileItemWriter repayOrderNewMultiResourceFlatFileItemWriter;

    @PostConstruct
    private void init(){

        Map<String,ItemWriter> map = new HashMap<>();
        //真正写文件的writer不能是同一个实例，否则会出现问题
        //map.put("3",repayOrderFlatFileItemWriter);
        map.put("3",repayOrderMultiResourceFlatFileItemWriter);
        map.put("0",repayOrderNewMultiResourceFlatFileItemWriter);

        this.setRouterDelegate(repayOrderRouterClassifiter);
        this.setMatcherMap(map);
    }

}
